import math
# 判断素数
def is_prime(n):
	t = int(math.sqrt(n))
	for i in range(2, t + 1):
		if(n % i == 0):
			return 0
	return 1
# 判断回文
def is_pal(n):
	stack = [0 for i in range(0, 15)]
	top = 0
	while(n != 0):
		top = top + 1
		stack[top] = n % 10
		n = n // 10
#	print(stack, top)
	i = 1
	j = top
	while(i <= j) :
		if(stack[i] != stack[j]):
			return 0
		i = i + 1
		j = j - 1
	return 1
s = input().split()
L = int(s[0])
R = int(s[1])
for i in range(L, R + 1):
	if(is_pal(i) and is_prime(i)):
		print(i)

#for i in range(L, R + 1):
#	print(i,is_pal(i))
